<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>

  <body>
    <div id="app">
      <h2>{{fullName}}</h2>
    </div>

    <script src="../js/vue.js"></script>
    <script>
      const app = new Vue({
        el: '#app',
        data: {
          firstName: 'Lebron',
          lastName: 'James'
        },
        computed: {
          // fullName: function() {
          //   return this.firstName + ' ' + this.lastName
          // }
          // name: '浮幻'

          // 计算属性一般不设置set方法，这样就成了只读属性
          fullName: {
            set: function (newValue) {
              console.log(newValue)
              let names = newValue.split(' ') // split方法是分割字符串
              this.firstName = names[0]
              this.lastName = names[1]
            },
            get: function () {
              return this.firstName + ' ' + this.lastName
            }
          }

          // 上面属性的简写
          // fullName: function() {
          //   return this.firstName + ' ' + this.lastName
          // }
        }
      })
    </script>
  </body>
</html>
